package com.zj.fx.service.info;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.mapper.info.InfoNecessaryMapper;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.info.InfoNecessary;
import com.zj.fx.model.info.InfoNecessaryExample;
import com.zj.fx.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 必备条件指标库表 InfoNecessaryService
 * @Title: InfoNecessaryService.java 
 * @Package com.zj.fx.service 
 * @author fuce_自动生成
 * @email ${email}
 * @date 2023-06-06 14:27:19  
 **/
@Service
public class InfoNecessaryService implements BaseService<InfoNecessary, InfoNecessaryExample> {
    @Autowired
    private InfoNecessaryMapper infoNecessaryMapper;


    /**
     * 分页查询
     * @param
     * @param
     * @return
     */
    public PageInfo<InfoNecessary> list(Tablepar tablepar,InfoNecessary infoNecessary) {
        InfoNecessaryExample testExample = new InfoNecessaryExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(infoNecessary);
        }
        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
        //	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<InfoNecessary> list = infoNecessaryMapper.selectByExample(testExample);
        PageInfo<InfoNecessary> pageInfo = new PageInfo<InfoNecessary>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        InfoNecessaryExample example = new InfoNecessaryExample();
        example.createCriteria().andIdIn(lista);
        return infoNecessaryMapper.deleteByExample(example);


    }


    @Override
    public InfoNecessary selectByPrimaryKey(String id) {

        return infoNecessaryMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(InfoNecessary record) {
        return infoNecessaryMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(InfoNecessary record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return infoNecessaryMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(InfoNecessary record, InfoNecessaryExample example) {

        return infoNecessaryMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(InfoNecessary record, InfoNecessaryExample example) {

        return infoNecessaryMapper.updateByExample(record, example);
    }

    @Override
    public List<InfoNecessary> selectByExample(InfoNecessaryExample example) {

        return infoNecessaryMapper.selectByExample(example);
    }


    @Override
    public long countByExample(InfoNecessaryExample example) {

        return infoNecessaryMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(InfoNecessaryExample example) {

        return infoNecessaryMapper.deleteByExample(example);
    }


    public List<InfoNecessary> selectAll() {
        InfoNecessaryExample infoNecessaryExample = new InfoNecessaryExample();
        InfoNecessaryExample.Criteria criteria = infoNecessaryExample.createCriteria();
        criteria.andIdIsNotNull();
        return infoNecessaryMapper.selectByExample(infoNecessaryExample);
    }
}
